module $Xrm {
    class _string {
        static isGuid(value: string): bool;
        static isNumber(value: string): bool;
        static format(...args: string[]): string;
        static insert(s: string, position: number, value: string): string;
        static pad(value: any, length?: number);
    }
    class _array {
        static getLength(array: any): number;
        static joinWithFormat(array: any, format: string): string;
    }
    class _xml {
        static getText(node): string;
        static getValue(node): any;
        static getChildNode(node, nodeName: string);
        static getAttribute(node, attributeName: string);
        static stripNamespace(nodeName: string): string;
    }
    class _date {
        static format(date: Date, mask: string): string;
    }
}

module $Xrm {
    class OrganizationService {
        private _sdkUrl;
        constructor(sdkUrl: string);
        public Associate(moniker1: EntityReference, moniker2: EntityReference, relationshipName: string): void;
        public AssociateAsync(moniker1: EntityReference, moniker2: EntityReference, relationshipName: string, callback?: () => void ): void;
        public Disassociate(moniker1: EntityReference, moniker2: EntityReference, relationshipName: string): void;
        public DisassociateAsync(moniker1: EntityReference, moniker2: EntityReference, relationshipName: string, callback?: () => void ): void;
        public Create(entity: Entity): string;
        public CreateAsync(entity: Entity, callback?: (id: string) => void ): void;
        public Update(entity: Entity): void;
        public UpdateAsync(entity: Entity, callback?: () => void ): void;
        public Retrieve(entityName: string, id: string, columnSet: any): Entity;
        public RetrieveAsync(entityName: string, id: string, columnSet: any, callback?: (entity: Entity) => void ): void;
        public RetrieveMultiple(fetchXml: string): Entity[];
        public RetrieveMultipleAsync(fetchXml: string, callback?: (entities: Entity[]) => void ): void;
        public Delete(entityName: string, id: string): void;
        public DeleteAsync(entityName: string, id: string, callback?: () => void ): void;
        public Execute(request: Messages.OrganizationRequest): Messages.OrganizationResponse;
        public ExecuteAsync(request: Messages.OrganizationRequest, callback?: (response: Messages.OrganizationResponse) => void ): void;
        private WashWithSoapHeader(operation, requestXml);
        private ExecuteAjaxRequest(operation, requestXml, async, callback?);
        private Encode(xml);
    }
}
module $Xrm {
    class Entity {
        public Id: string;
        public LogicalName: string;
        constructor(logicalName?: string, id?: string);
        public GetAttributeValue(attributeLogicalName: string): any;
    }
    class EntityReference {
        public LogicalName: string;
        public Id: string;
        public Name: string;
        constructor(logicalName?: string, id?: string);
    }
    class Money {
        public Value: number;
        constructor(value?: number);
    }
    class OptionSetValue {
        public Value: number;
        constructor(value?: number);
    }
    class FetchExpression {
        public Query: string;
        constructor(query?: string);
    }
    class EntityMetadata {
        constructor();
        public get (index: string);
    }
}

module $Xrm.Messages {
    class AssignRequest extends OrganizationRequest {
        public Assignee: EntityReference;
        public Target: EntityReference;
        constructor();
        public GetResponse(responseXml: Document): AssignResponse;
        public ToSoapXml(): string;
    }
    class AssignResponse extends OrganizationResponse {
        constructor(responseXml?: Document);
    }
}

module $Xrm.Messages {
    class AssociateEntitiesRequest extends OrganizationRequest {
        public Moniker1: EntityReference;
        public Moniker2: EntityReference;
        public RelationshipName: string;
        constructor();
        public GetResponse(responseXml: Document): AssociateEntitiesResponse;
        public ToSoapXml(): string;
    }
    class AssociateEntitiesResponse extends OrganizationResponse {
        constructor(responseXml?: Document);
    }
}

module $Xrm.Messages {
    class CreateRequest extends OrganizationRequest {
        public Target: Entity;
        constructor();
        public GetResponse(responseXml: Document): CreateResponse;
        public ToSoapXml(): string;
    }
    class CreateResponse extends OrganizationResponse {
        public Id: string;
        constructor(responseXml?: Document);
        public BindProperties(): void;
    }
}

module $Xrm.Messages {
    class DisassociateEntitiesRequest extends OrganizationRequest {
        public Moniker1: EntityReference;
        public Moniker2: EntityReference;
        public RelationshipName: string;
        constructor();
        public GetResponse(responseXml: Document): DisassociateEntitiesResponse;
        public ToSoapXml(): string;
    }
    class DisassociateEntitiesResponse extends OrganizationResponse {
        constructor(responseXml?: Document);
    }
}
module $Xrm.Messages {
    class ErrorResponse {
        public ResponseXml: Document;
        public ResponseText: string;
        public Error: string;
        constructor(responseXml: Document, responseText: string);
        private ParseError();
    }
}

module $Xrm.Messages {
    class ExecuteWorkflowRequest extends OrganizationRequest {
        public EntityId: string;
        public WorkflowId: string;
        constructor();
        public GetResponse(responseXml: Document): ExecuteWorkflowResponse;
        public ToSoapXml(): string;
    }
    class ExecuteWorkflowResponse extends OrganizationResponse {
        public Id: string;
        constructor(responseXml?: Document);
        public BindProperties(): void;
    }
}

module $Xrm.Messages {
    class OrganizationRequest {
        static XmlNamespaces: {
            a: string;
            b: string;
            c: string;
            i: string;
            metadata: string;
        };
        public RequestId: string;
        public RequestName: string;
        public Parameters: any[];
        private _requestNamespace;
        constructor(requestName?: string, requestNamespace?: string);
        public GetResponse(responseXml: Document): OrganizationResponse;
        public ToSoapXml(): string;
        private BuildParameterSoapXml();
        private BuildEntityParameters(value, valueXml);
        private BuildParameterValue(key, value);
        private BuildEntityReferenceValueParameter(value);
    }
    class OrganizationResponse {
        public ResponseName: string;
        public Results: any[];
        constructor(responseName?: string, responseXml?: Document);
        public BindProperties(): void;
        public ParseResponse(responseXml: Document): void;
    }
}

module $Xrm.Messages {
    class RetrieveRequest extends OrganizationRequest {
        public Target: EntityReference;
        public ColumnSet: any;
        constructor(target?: EntityReference, columnSet?: any);
        public GetResponse(responseXml: Document): RetrieveResponse;
        public ToSoapXml(): string;
    }
    class RetrieveResponse extends OrganizationResponse {
        public Entity: Entity;
        constructor(responseXml?: Document);
        public BindProperties(): void;
        public ParseResponse(responseXml: Document): void;
    }
}

module $Xrm.Messages {
    class RetrieveEntityRequest extends OrganizationRequest {
        public EntityFilters: string;
        public MetadataId: string;
        public RetrieveAsIfPublished: bool;
        public LogicalName: string;
        constructor();
        public GetResponse(responseXml: Document): RetrieveEntityResponse;
        public ToSoapXml(): string;
    }
    class RetrieveEntityResponse extends OrganizationResponse {
        public EntityMetadata: EntityMetadata;
        constructor(responseXml?: Document);
        public BindProperties(): void;
        public ParseResponse(responseXml: Document): void;
        private ParseNested(node, metadataField);
    }
}

module $Xrm.Messages {
    class RetrieveMultipleRequest extends OrganizationRequest {
        public Query: FetchExpression;
        constructor(query?: FetchExpression);
        public GetResponse(responseXml: Document): RetrieveMultipleResponse;
        public ToSoapXml(): string;
    }
    class RetrieveMultipleResponse extends OrganizationResponse {
        public Entities: Entity[];
        constructor(responseXml?: Document);
        public BindProperties(): void;
        public ParseResponse(responseXml: Document): void;
        private static GetValueFromXml(type, valueNode);
        private static ParseResults(resultsNode);
    }
}

module $Xrm.Messages {
    class SendEmailRequest extends OrganizationRequest {
        public EmailId: string;
        public IssueSend: bool;
        public TrackingToken: string;
        constructor();
        public GetResponse(responseXml: Document): SendEmailResponse;
        public ToSoapXml(): string;
    }
    class SendEmailResponse extends OrganizationResponse {
        public Subject: string;
        constructor(responseXml?: Document);
        public BindProperties(): void;
    }
}

module $Xrm.Messages {
    class SetStateRequest extends OrganizationRequest {
        public EntityMoniker: EntityReference;
        public State: OptionSetValue;
        public Status: OptionSetValue;
        constructor();
        public GetResponse(responseXml: Document): SetStateResponse;
        public ToSoapXml(): string;
    }
    class SetStateResponse extends OrganizationResponse {
        constructor(responseXml?: Document);
    }
}

module $Xrm.Messages {
    class UpdateRequest extends OrganizationRequest {
        public Target: Entity;
        constructor();
        public GetResponse(responseXml: Document): UpdateResponse;
        public ToSoapXml(): string;
    }
    class UpdateResponse extends OrganizationResponse {
        constructor(responseXml?: Document);
    }
}

module $Xrm.Messages {
    class WhoAmIRequest extends OrganizationRequest {
        constructor();
        public GetResponse(responseXml: Document): WhoAmIResponse;
        public ToSoapXml(): string;
    }
    class WhoAmIResponse extends OrganizationResponse {
        public UserId: string;
        public BusinessUnitId: string;
        public OrganizationId: string;
        constructor(responseXml?: Document);
        public BindProperties(): void;
    }
}